package com.heima.kafka.producer;

import org.apache.kafka.clients.producer.*;

import java.util.Properties;
import java.util.concurrent.ExecutionException;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/2/4 11:26
 * @Version 1.0
 */
public class ProducerTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Properties properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.200.130:9092");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String,String> producer = new KafkaProducer<String, String>(properties);

        ProducerRecord<String, String> kvProducerRecord = new ProducerRecord<>("topic-news", 1,"hello", "hello kafka!");
//        RecordMetadata recordMetadata = producer.send(kvProducerRecord).get();
        producer.send(kvProducerRecord, (recordMetadata, e) -> System.out.println("----->"+recordMetadata.offset()));
        System.out.println("我是证明我要先打印");

        producer.close();
    }
}